package baiwa.rta.security;

/*
 *
 * Kroekpong Sakulchai
 * File Name : PasswordEncoder.java
 * Date : Feb 27, 2014 : Time : 8:55:42 AM
 * Description :
 *
 */
import org.apache.log4j.Logger;
import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

public class CustomPasswordEncoder implements PasswordEncoder {
	private final static Logger logger = Logger.getLogger(CustomPasswordEncoder.class);
	private final static Md5PasswordEncoder encoder = new Md5PasswordEncoder();

	public static String encode(String userInput) {
		return encoder.encodePassword(userInput, null);
	}

	@Override
	public boolean matches(CharSequence userInput, String password) {

		if (password == null) {
			return false;
		}
		return (password).equals(encoder.encodePassword(String.valueOf(userInput), null)) ? true : false;
	}
	
	public static void main(String[] args) {
		System.out.println(encoder.encodePassword("password", null));
	}

	@Override
	public String encode(CharSequence arg0) {
		// TODO Auto-generated method stub
		return null;
	}
	
}
